﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using DingApi.Models;
using System.Data;

using System.Web;
using Dingding.Helper;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NCommon;


namespace DingApi.Controllers
{
    [RoutePrefix("api/Index")]
    public class IndexController : ApiController
    {   

         

        [HttpPost]
        [Route("PostIndex_Load")]

        //授权
        public System.Data.DataSet PostIndex_Load([FromBody]  JObject obj)
        {

           string staff_id=  obj["USERID"] == null ? " " : obj["USERID"].ToString();

           string appid     = obj["APPID"] == null ? "LTPA" : obj["APPID"].ToString();
           string bill_type = "";
            if (appid=="LTPA")
            {
                bill_type = "88";
            }
            else if (appid=="LTJY")
            {
                bill_type = "89";
            }
            else if (appid == "LTNM")
            {
                bill_type = "LTNM";
            }

            else if (appid == "SHKJ")
            {
                bill_type = "99";
            }
            else
            {
                bill_type = "88";
            }

           string str1  =  " select distinct class_code,class_desc,type_no  from  tpabma21 ";
                str1    += " where   (select extend_2 from tpabma2 ";
                str1 += " where bill_type = '" + bill_type + "' and staff_id = '" + staff_id + "') ";
                str1    += " like '%' ||  form_no || '%'";  
                str1 += " and func_name = '"+ appid + "' "; 

                str1 += " order by  type_no";
              
           string str2  =  " select * from  tpabma21 ";
                str2    += " where   (select extend_2 from tpabma2 ";
                str2 += " where bill_type = '" + bill_type + "' and staff_id = '" + staff_id + "') ";
                str2    += " like '%' ||  form_no || '%'";
                str2 += " and  FUNC_NAME='" + appid + "'";
                str2    += " order by  seq_now";




            EI.EIInfo outBlock = EF.Utility.ExecQuery(str1);
            EI.EIInfo outBlock2 = EF.Utility.ExecQuery(str2);
             
            outBlock2.Tables[0].TableName = "Table1";


            outBlock.Tables.Add(outBlock2.Tables[0].Copy());
             

            //系统信息；
            outBlock.Tables.Add("SYS");
            outBlock.Tables["SYS"].Columns.Add("FLAG");
            outBlock.Tables["SYS"].Columns.Add("MSG");
            outBlock.Tables["SYS"].Rows.Add(outBlock.sys_info.flag, outBlock.sys_info.msg);
            return outBlock;


        }


       
 
    }
}